<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>异常信息</title>

    <link rel="stylesheet" th:href="@{/static/iview/iview.css}">
    <script th:src="@{/static/libs/jquery-3.2.1.min.js}" type="text/javascript"></script>
	<script th:src="@{/static/libs/vue.min.js}" type="text/javascript"></script>
	<script th:src="@{/static/layer/layer.js}" type="text/javascript"></script>
   <script th:src="@{/static/iview/iview.min.js}" type="text/javascript"></script>
	<script th:src="@{/static/common.js}" type="text/javascript"></script>
    <style type="text/css">
	[v-cloak] {
			  display: none;
			}
	</style>
</head>
<body>
<div id="app" v-cloak>
        <div style="margin-bottom: 6px;margin: 30px">
			<i-input v-model="content" placeholder="查询"  style="width: 200px"></i-input>
			<i-select  v-model="transtype"  style="width: 150px" @on-change="changtranstypelist"  placeholder="交易类型" >
		              <i-option v-for="item in transtypelist"  :value="item.id"  :key="item.value">{{item.id}} - {{item.value}} </i-option>
		     </i-select> 
		      
			<i-select  v-model="errortype"  style="width: 150px" @on-change="changerrortypelist"  placeholder="异常类型 "> 
		              <i-option v-for="item in errortypelist"  :value="item.id"  :key="item.value">{{item.id}} - {{item.value}} </i-option>
		     </i-select> 
		    <date-picker type="datetime" v-model="startTime" placeholder="开始时间" :options="startTimeOption" @on-change="onStartTimeChange"   style="width: 153px" ></date-picker>
		    -
		     <date-picker type="datetime" v-model="endTime" placeholder="结束时间" :options="endTimeOption" @on-change="onEndTimeChange"   style="width: 153px" ></date-picker>
			<i-button type="primary" @click="search()" icon="ios-search">搜索</i-button>
			<i-button type="primary" @click="empty()" icon="ios-close-empty">清空</i-button>
			<i-button type="primary" @click="expError()" icon="el-icon-download">导出</i-button>
		</div>
		<div style="margin-bottom: 6px;margin: 30px">
			<template> 
				<i-table border :content="self" :columns="tableTitle" :data="datalist"></i-table>
			 	<br>
<!-- 			 	<Page :total="dataCount" :page-size="pageSize" show-total @on-change="changepage" @on-page-size-change="changePageSize"></Page> -->
			 	<!--分页功能-->
				<Page :current="1" :total="dataCount" :page-size="pageSize"  @on-change="changepage"  show-elevator show-sizer show-total></Page>
				 
			</template>
		</div>
</div>
<script type="text/javascript">
var vm = new Vue({
	el : '#app',
	data : {
		content : '',
		pageNo : 0,
		pageSize : 10,// 每页显示多少条
		dataCount:"", // 总数据的条目
		datalist: [], //接口获取的总数据
		transtype:'',
		transtypelist:[
			{"id":"","value":"请选择"},
			{"id":"1","value":"入口"},
			{"id":"2","value":"出口"},
			{"id":"3","value":"门架"},
			{"id":"4","value":"车牌识别"},
			{"id":"5","value":"门架心跳"},
			{"id":"6","value":"车道心跳"},
			{"id":"7","value":"车道、门架统计数据"},
			{"id":"8","value":"车道门架监测数据"},
			{"id":"9","value":"ETC门架基础信息"},
			{"id":"10","value":"门架图片（按需全量）"},
			{"id":"11","value":"门架图片（失败未匹配）"},
			{"id":"12","value":"ETC门架运行状态"},
			{"id":"13","value":"ETC门架异常事件"},
			{"id":"14","value":"门架交易小时批次"},
			{"id":"15","value":"门架牌识小时批次"},
			{"id":"16","value":"上传异常数据调取"},
			{"id":"17","value":"上传异常数据修正"},
			{"id":"18","value":"清分上传"},
			{"id":"19","value":"清分下载"},
			{"id":"20","value":"营改增交易发票基础数据上传"}
		], 
		errortype:'',
		errortypelist:[
			{"id":"","value":"请选择"},
			{"id":"0","value":"文件数据解析失败(json格式不对、文件不完整)"},
			{"id":"1","value":"数据校验失败(非空校验、业务属性校验)"},
			{"id":"2","value":"json数据文件不合规"},
			{"id":"3","value":"数据校验不合规"},
			{"id":"4","value":"数据重复"},
			{"id":"5","value":"入库失败"},
			{"id":"6","value":"其他"}
		], 
		startTime: '',
        endTime: '',
        startTimeOption: {},
        endTimeOption: {},
		historyData:'',//展示的数据 
		shows:'',
		loadingText: '',
		tableTitle:[ 
		{
		   title : "编号",
		   type: 'index',
		   align: 'center',
            width: 70
		 },
		{
			key : "fileName",
			title : "文件名",
			width : 155,
			render : function(h, params) {
				 return h('a',{attrs:{href: "/monitor/downLoadFile?"+window.btoa("id="+params.row.id+"&type=file"),target: '_black'}},params.row.fileName);
			}
		},
		{
			key : "transType",
			title : "交易类型",
			width : 150,
			render : function(h, params) {
					var text = " - 未定义类型";
				if(params.row.transType == 1){
					text =" -入口";
				}else	 if(params.row.transType == 2){
					text =" - 出口";
				}else	 if(params.row.transType == 3){
					text =" - 门架";
				}else	 if(params.row.transType == 4){
					text =" - 车牌识别";
				}else	 if(params.row.transType == 5){
					text =" - 门架心跳";
				}else	 if(params.row.transType == 6){
					text =" - 车道心跳";
				}else	 if(params.row.transType == 7){
					text =" - 车道、门架统计数据";
				}else	 if(params.row.transType == 8){
					text =" - 车道门架监测数据";
				}else	 if(params.row.transType == 9){
					text =" - ETC门架基础信息";
				}else	 if(params.row.transType == 10){
					text =" - 门架图片（按需全量）";
				}else	 if(params.row.transType == 11){
					text =" - 门架图片（失败未匹配）";
				}else	 if(params.row.transType == 12){
					text =" - ETC门架运行状态";
				}else	 if(params.row.transType == 13){
					text =" - ETC门架异常事件";
				}else	 if(params.row.transType == 14){
					text =" - 门架交易小时批次";
				}else	 if(params.row.transType == 15){
					text =" - 门架牌识小时批次";
				}else	 if(params.row.transType == 16){
					text =" - 上传异常数据调取";
				}else	 if(params.row.transType == 17){
					text =" - 上传异常数据修";
				}else	 if(params.row.transType == 18){
					text =" - 清分上传";
				}else	 if(params.row.transType == 19){
					text =" - 清分下载";
				}
				  return h('div',params.row.transType+text);
			}
		}, 
		{
			key : "errType",
			title : "异常类型",
			width : 90,
			render : function(h, params) {
				var text = " - 未定义类型";
				if(params.row.errType == 0){
					text =" - 件数据解析失败(json格式不对、文件不完整)";
				}else	 if(params.row.errType == 1){
					text =" - 数据校验失败(非空校验、业务属性校验)";
				}else	 if(params.row.errType == 2){
					text =" - json数据文件不合规";
				}else	 if(params.row.errType == 3){
					text =" - 数据校验不合规";
				}else	 if(params.row.errType == 4){
					text =" - 数据重复";
				}else	 if(params.row.errType == 5){
					text =" - 入库失败";
				}else	 if(params.row.errType == 6){
					text =" - 其他";
				}
				 return h('div',params.row.errType + text);
			}
		}, {
			key : "errDesc",
			title : "异常描述",
			render : function(h, params) {
				 return h('div', [
					 //隐藏起来
					 h('span', { style: { display: 'none' },attrs:{"ref": "shows"}, },params.row.errDesc),
					 //显示部分
				     h('span', {
				        	 slot: 'content',
				            style: {
			                    display: 'inline-block',
			                    width: params.column._width*0.9+'px',
			                    overflow: 'hidden',
			                    textOverflow: 'ellipsis',
			                    whiteSpace: 'nowrap'
			                } 
				        },params.row.errDesc),
				        //h('a',{attrs:{href: "/monitor/downLoadFile?"+window.btoa("id="+params.row.id+"&type=errDesc"),target: '_black'}},"下载"),
				        h('a',{on:{click: (e) =>{
							   var el = e.currentTarget;
							   var first = el.previousSibling.previousSibling;
							   var second = el.previousSibling;						   
				        	   if(first.style.display == 'none'){
				        		   first.style.display = "inline-block";
				        		   el.innerText = '收缩';
					        	   el.innerHTML= '收缩';
				        	   }else{
				        		   first.style.display = "none";
				        		   el.innerText = '展开';
				        		   el.innerHTML= '展开';
				        	   }
				        	   
				        	   //缩略图
				        	   if(second.style.display == 'none'){
				        		   second.style.display = "inline-block";
				        		   el.innerText = '展开';
				        		   el.innerHTML= '展开';
				        	   }else{
				        		   second.style.display = "none";
				        		   el.innerText = '收缩';
				        		   el.innerHTML= '收缩';
				        		
				        	   }
				        	   
				        }}},"展开")
				        	
				    ]);
			}
		}, 
		{
			key : "status",
			title : "状态",
			width : 150,
			render : function(h, params) {
				var text = "未定义状态";
				if(params.row.status == 0){
					text ="0 - 待处理(默认)";
				}else	 if(params.row.status == 1){
					text ="1 - 已处理";
				}else	 if(params.row.status == 2){
					text ="2 - 失败(放弃处理或处理失败)";
				}
				  return h('div',text);
			}
		},
		{
			key : "createTime",
			title : "创建时间",
			width : 150,
			render : function(h, params) {
				  return h('div',
						  formatDate(new Date(params.row.createTime),'yyyy-MM-dd hh:mm:ss'));
			}
		}/*, {
			title : '操作',
			key : 'action',
			width : 90,
			align : 'left',
			render : function(h, params) {
				var functionList = [];
				//修改
				var edit = h('Button', {
					props : {
						type : 'primary',
						size : 'small',
						icon : 'edit'
					},
					style : {
						marginRight : '8px'
					},
					on : {
						click : function() {
							vm.edit(params.row);
						}
					}
				}, '修改');
				functionList.push(edit);
		
				// 返回方法集合
				return h('div', functionList);
			}
		}*/ ]	
	},
	methods : {
		//搜索
		search : function(){
			this.loadlist(1);
		},
		empty : function(){
			vm.content = '';
			vm.transtype='';
			 vm.errortype='';
		     vm.startTime='';
		    vm.endTime='';
			this.loadlist(1);
		},expError:function(){
			var page = {};
			page['pageIndex']= this.pageNo;
			page['pageSize']= this.pageSize;
					
			var params = {};
			var contentValue = this.content.trim();
			if(contentValue !=''){
				params['fileName'] = contentValue;
			}
			
			if(this.transType!=''){
				params['transType'] = parseInt(this.transType);
			}
			
			if(this.errType !=''){
				params['errType'] = parseInt(this.errType);
			}
			
			if(this.startTime !=''){
				params['beginTime'] =  formatDate(new Date(this.startTime),'yyyy-MM-dd hh:mm:ss');
			}
			
			if(this.endTime !=''){
				params['endTime'] =  formatDate(new Date(this.endTime),'yyyy-MM-dd hh:mm:ss');
			}
			
			 var conditional = {};
			 conditional['page'] = page;
			 conditional['params'] = params;
			 
			var json =  JSON.stringify(conditional);
			
			
			axios({
				 method: 'post',
				 url:"../monitor/exportErrorDataFile",
				 data: {
					 firstName: 'Fred',
				 	lastName: 'Flintstone'
				 },
				 responseType: 'blob'
			}).then(response => {
				 this.download(response)
			}).catch((error) => {

			})
			
			
		/* 	$.ajax({
				url:"../monitor/exportErrorDataFile",
				dataType:'blob',
				type:"post",
				data: json,
				success: function(data,arg2,request) {
					 console.log(data);
					 console.log(arg2);
					 console.log(request.responseXML);
					if(data.err_code !='200'){   
						top.layer.msg('导出失败', {icon: 1});
                    }
				},
				done:function (response) {
					 console.log(response);
				}
			}); */
		},
		 download (data) {
			 if (!data) {
			  return
			 }
			 let url = window.URL.createObjectURL(new Blob([data]))
			 let link = document.createElement('a')
			 link.style.display = 'none'
			 link.href = url
			 link.setAttribute('download', 'excel.xlsx')
			 
			 document.body.appendChild(link)
			 link.click()
	    },
		loadlist : function(index) {
			var page = {};
			page['pageIndex']= this.pageNo;
			page['pageSize']= this.pageSize;
					
			var params = {};
			var contentValue = this.content.trim();
			if(contentValue !=''){
				params['fileName'] = contentValue;
			}
			
			if(this.transType!='' && !isNaN(this.transType)){
				params['transType'] = parseInt(this.transType);
			}
			
			if(this.errType !=''  && !isNaN(this.errType)){
				params['errType'] = parseInt(this.errType);
			}
			
			if(this.startTime !=''){
				params['beginTime'] =  formatDate(new Date(this.startTime),'yyyy-MM-dd hh:mm:ss');
			}
			
			if(this.endTime !=''){
				params['endTime'] =  formatDate(new Date(this.endTime),'yyyy-MM-dd hh:mm:ss');
			}
			
			if(this.startTime !='' &&  this.endTime ==''){
				params['endTime'] =  formatDate(new Date(),'yyyy-MM-dd hh:mm:ss');
			}else if(this.startTime =='' &&  this.endTime !=''){
				if(this.endTime !=''){
					params['beginTime'] =  formatDate(new Date(this.endTime),'yyyy-MM-dd hh:mm:ss');
				}
			}
			
		
			
			 var conditional = {};
			 conditional['page'] = page;
			 conditional['params'] = params;
			 
			var json =  JSON.stringify(conditional);
		
			 var conditional = {};
			 conditional['page'] = page;
			 conditional['params'] = params;
			 
			var json =  JSON.stringify(conditional);
			
			$.ajax({
				url:"../monitor/getErrorDataList",
				type:"post",
				dataType: "json",
				contentType: 'application/json', 
				data: json,
				success: function(data) {
					vm.datalist = data.result.rows;
					vm.dataCount = data.result.total; //接口返回数据的总条目数
					if(vm.dataCount < vm.pageSize){   
                        vm.historyData   = vm.JobData
                    }else{
                        vm.historyData = vm.datalist.slice(0,self.pageSize);
                    }
				}
			});
		},
        changepage(index){
			this.loadlist(index);
        },
        changtranstypelist:function(value){
        	 vm.transtype=value;
        },
        changerrortypelist:function(valie){
        	 vm.errortype=value;
        },
        onStartTimeChange(startTime, type) {
            this.endTimeOption = {
                disabledDate(endTime) {
                    return endTime < new Date(startTime) || endTime > Date.now()
                }
            }
        },
        onEndTimeChange(endTime, type) {
            this.startTimeOption = {
                disabledDate(startTime) {
                    return startTime > new Date(endTime) || startTime > Date.now()
                }
            }
        },
		edit : function(quartz){
			dialogOpen({
				title: '修改',
				url: 'task/add.shtml',
				//屏幕小 滚动条显示
				scroll : true,
				width: '450px',
				height: '450px',
				success : function(iframeId){
					top.frames[iframeId].vm.formQuartz = quartz;
				},
				yes : function(iframeId) {
					top.frames[iframeId].vm.acceptClick();
				},
			});
		},
		//移除任务
		remove : function(jobName,jobGroup){
			var that = this;
			top.layer.confirm('确定要移除任务吗？', {btn: ['确定','取消']}, function(){
				$.ajax({
					url:"../job/remove",
					type:"post",
					data:{'time':(new Date()).toString(),"jobName":jobName,'jobGroup':jobGroup},
					success: function(result) {
						if(result.code=="0"){
							top.layer.msg('任务移除成功', {icon: 1});
							window.setTimeout(that.loadlist(),1500); 
						}
					}
				});
			});
		}
	},
	created : function() {
		 this.loadlist();
         //this.changepage(0);
	}
})

</script>
</body>
</html>